#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <glib.h>

#include "spicy.h"
#include "vcd-common-api/vcd-util.h"
#include "vcd-common-api/vcd-log.h"
#include "vcd-common-api/trace-signals/libdebug.h"
#include "vcd-common-api/vcd-json-parser.h"
#include "vcd-common-api/vcd-crypto.h"
#include "vcd-linux-ui/vcd-message-dialog.h"


void fake_login(char *argv[]){

    spice_connect_data scd = {0};

    vcd_common_init_platform();
    //vcd_common_init_some_path(argv[0],&scd);
    //vcd_log_init_with_log4crc_logdir(scd.log4crc_path,scd.log_dir);

    // use Vclient
    //setVcdClientFlg(TRUE);

#if 1
    const char* host = "192.168.199.162";
    const char* port = "61000";
    const char* pass = "123";
    const char* proxy = NULL;

    scd.use_rdp = TRUE;
    sprintf(scd.rdp_host,"%s","192.168.199.241");
    sprintf(scd.rdp_port,"%s","3389");
    scd.use_guest_user_pass = TRUE;
    sprintf(scd.guest_name,"%s","root");
    sprintf(scd.guest_pass,"%s","123");
    scd.rdp_stream_path = "C:\\msys32\\home\\feng\\freerdp\\build\\Debug\\wfreerdp.exe";
    //scd.rdp_stream_path = "C:\\msys32\\home\\feng\\freerdp\\build\\Debug\\wfreerdp.exe";

//    const char* host = "pvespiceproxy:5e3ac68c:101:v-ojrf5m9l::412ec6aa133589dfeacb747bf9fa28fea3511618";
//    const char* port = "61000";
//    const char* pass = "123";
//    const char* proxy = "http://vdp.verycloud.cn:3128";
#else
    const char* host = scd.host;
    const char* port = scd.port;
    const char* pass = scd.password;
#endif

    //spicy_connect(host,port,pass,NULL);
    spicy_connect_with_priv(host,port,pass,proxy,&scd);

    gtk_main();
}

void test_dialog(){
    const char* path = "C:/Program Files (x86)/verycloud/VeryClient/share/img";
    vcd_common_set_img_path(path);

    message_diag_context *t = g_malloc0(sizeof(message_diag_context));
    t->info = "设备未开启，是否开启设备？";
    vcd_message_dialog(t);
}

void test_domain(){
    vcd_common_init_platform();
    //const char* host = "192.168.32.60";
    //const char* host = "vcp.verycloud.cn";
    const char* host = "vdp.verycloud.cn";
    //const char* host = "www.baidu.com";
    //char* ip = vcd_common_resolve_domain(host);
    //printf("ip:%s\n",ip);
    printf("ssssssssssss\n");
    fprintf(stderr, "111111111111\n");
}


void test_crypto(){
    const char* str = "IYkayUMVNvBTTZmBOZMFtY203rHxbW8xtNMNnZHaxPBV4p0chaDfGZFV7XmGAY0w7OMAIWMExHAvhckcINwW6YV72wWds_q";
    //vcd_common_url_decode(pStart);
    //M_DEBUG("url_decode:%s",pStart);

    char json_str[1024] = {0};
    vcd_decode_crypto(str,json_str);
    printf("crytpo:%s\n",json_str);
}


int main(int argc, char *argv[]){

    gtk_init(&argc, &argv);

    //vcd_message_dialog_logining();
    //vcd_message_dialog_logining_with_gif("../img/loading300x250.gif",0);
    //test_dialog();
    fake_login(argv);
    //test_domain();

    //test_crypto();
    gtk_main();
    return 0;
}
